package com.example.sharesinfo.fragment.stock;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.androidkun.xtablayout.XTabLayout;
import com.example.sharesinfo.R;
import com.example.sharesinfo.adapter.MyPagerAdapter;

import java.util.ArrayList;
import java.util.List;


public class MarketAStocksFragment extends Fragment {
    private List<Fragment> fragments = new ArrayList<>();
    private List<String> titles = new ArrayList<>();
    private XTabLayout mTableLayout;
    private ViewPager mViewPager;
    private MarketHuShenFragment mMarketHuShenFragment;
    private MarketBanKuaiFragment mMarketBanKuaiFragment;
    private MarketKeChuangFragment mMarketKeChuangFragment;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_market_astocks, null);
        initData();
        initView(view);
        return view;
    }

    private void initView(View view) {
        mTableLayout = view.findViewById(R.id.market_a_stocks_tl_tabs);
        mViewPager = view.findViewById(R.id.market_a_stocks_vp_view);
        mViewPager.setAdapter(new MyPagerAdapter(getFragmentManager(), getContext(), fragments, titles));
        mTableLayout.setupWithViewPager(mViewPager);//此方法就是让tablayout和ViewPager联动
    }

    private void initData() {
        mMarketHuShenFragment = new MarketHuShenFragment();
        mMarketBanKuaiFragment = new MarketBanKuaiFragment();
        mMarketKeChuangFragment = new MarketKeChuangFragment();
        fragments.add(mMarketHuShenFragment);
        fragments.add(mMarketBanKuaiFragment);
        fragments.add(mMarketKeChuangFragment);
        titles.add("沪深");
        titles.add("板块");
        titles.add("科创板");

    }

}
